package cybercode.carsaleserver.config.redis;

import io.lettuce.core.api.sync.RedisCommands;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


@Component
@Log4j2
public class LettuceUtil {
    private static RedisCommands<String, String> commands;

    @Autowired
    private LettuceConfig lc;



    @PostConstruct
    void init() {
        commands = lc.getSyncCommand();
    }

    public static boolean exists(String key){
        return commands.exists(key) > 0;
    }


    public static long delCache(String key) {
        return commands.del(key);
    }

    public static void setStringCache(String key, String value, long expire) {
        commands.set(key, value);
        if (expire > 0) {
            commands.expire(key, expire);
        }
    }

    public static String getStringCache(String key) {
        return commands.get(key);
    }




}
